package com.stox.core.dao.mapper;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.stox.core.model.Index;

public class IndexRowMapper implements RowMapper<Index> {

	public static final String createSql = "create table index_(" +
			"code varchar(50) not null," +
			"name varchar(50) not null," +
			"exchangeCode varchar(20) not null," +
			"primary key (code))";
	public static final String createScripMappingSql = "create table index_scrip(" +
			"indexcode varchar(50) not null," +
			"scripcode varchar(20) not null," +
			"primary key (indexcode,scripcode))";
	public static final String createIndexSql = "create unique index index_index on index_(code)";
	public static final String selectSql = "select i.code, i.name, i.exchangeCode from Index i ";
	public static final String insertSql = "";
	
	
	@Override
	public List<Index> map(ResultSet rs) throws SQLException {
		List<Index> indexes = new ArrayList<Index>();
		while(rs.next()){
			Index index = new Index();
			indexes.add(index);
			index.setCode(rs.getString("code"));
			index.setName(rs.getString("name"));
			index.setExchangeCode(rs.getString("exchangeCode"));
		}
		return indexes;
	}

	@Override
	public void map(PreparedStatement ps, Index index) throws SQLException {
		if(index != null){
			ps.setString(1, index.getCode());
			ps.setString(2, index.getName());
			ps.setString(3, index.getExchangeCode());
		}
	}
}
